// pages/moment/moment.js
import { request } from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({

    /**
     * Page initial data
     */
    data: {
        isCard: true,
        Cates: [],
        imgList: []
    },

    /**
     * Publish 跳转
     */
    onTapPublish() {
        wx.navigateTo({
            url: '/pages/publish/publish',
        })
    },

    /**
     * Lifecycle function--Called when page load
     */
    onLoad: function (options) {
        this.getMomentInfo()
    },

    // get Moment API data
    async getMomentInfo() {
        // 1. 使用 es7 async await 发送异步请求
        const res = await request({url: "/momentInfo"});
        console.log(res.data.data)
        
        // 2. 赋值给 AppData
        let Cates = res.data.data
        let perImgList = []
        let imgAllList = []
        for (var i = 0; i < Cates.length; i++) {
            // console.log(Cates[i])
            perImgList = Cates[i].imgURL.split(',')
            // console.log(perImgList)
            imgAllList.push(perImgList)
        }
        console.log(imgAllList)

        this.setData({
            Cates,
            imgList: imgAllList
        })
    },

    /**
     * Lifecycle function--Called when page is initially rendered
     */
    onReady: function () {

    },

    /**
     * Lifecycle function--Called when page show
     */
    onShow: function () {

    },

    /**
     * Lifecycle function--Called when page hide
     */
    onHide: function () {

    },

    /**
     * Lifecycle function--Called when page unload
     */
    onUnload: function () {

    },

    /**
     * Page event handler function--Called when user drop down
     */
    onPullDownRefresh: function () {
        // Pull Down Event
        // 1. 重置数组
        this.setData({
            Cates:[],
            imgList: []
        })
        // 2. 重新发送请求
        this.getMomentInfo();
        // 3. 数据请求回来，手动关闭下拉刷新效果
        wx-wx.stopPullDownRefresh();
    },

    /**
     * Called when page reach bottom
     */
    onReachBottom: function () {

    },

    /**
     * Called when user click on the top right corner to share
     */
    onShareAppMessage: function () {

    }
})